package com.nightpiter;

import static com.nightpiter.controller.log.Logger.logProfilerBegin;
import static com.nightpiter.controller.log.Logger.logProfilerEnd;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.nightpiter.controller.FileLister;
import com.nightpiter.controller.MetroController;
import com.nightpiter.model.MetroModel;
import com.nightpiter.view.MetroView;

public class NightPiter extends Activity {

	private MetroModel model;
	private MetroView view;
	private MetroController controller;

	private AlertDialog ad;
	FileLister fl;

	/** Called when the activity is first created. */
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);

		com.nightpiter.controller.log.Logger.openLog(this);

		initMVC();

		com.nightpiter.controller.log.Logger.saveLog();

	}

	private void initMVC() {

		logProfilerBegin("Instantiating MVC components");
		this.model = new MetroModel(this);
		this.view = new MetroView(this);
		this.controller = new MetroController(this);
		logProfilerEnd("All components have been instantiated");

		logProfilerBegin("Calling MVC components init() methods");
		this.getModel().init();
		this.getView().init();
		this.getController().init();
		logProfilerEnd("MVC init complete");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, 0, "Open new map").setIcon(R.drawable.openmap2);
		menu.add(1, 1, "Zoom").setIcon(R.drawable.zoom3);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(Menu.Item item) {
		switch (item.getId()) {
		case 0:
			this.view.onOpenFileMenuItemSelected();
			return true;
		case 1:
			this.view.onZoomMenuItemSelected();
			return true;
		}
		return false;
	}

	/**
	 * @return the model
	 */
	public MetroModel getModel() {
		return model;
	}

	/**
	 * @return the view
	 */
	public MetroView getView() {
		return view;
	}

	/**
	 * @return the controller
	 */
	public MetroController getController() {
		return controller;
	}
}
